package y23.Sep;

public class Test21 {
    public static void main(String[] args) {
        System.out.println(StrToInt("-123455678"));

    }
    public static int StrToInt(String str) {
        if(str == null){
            return 0;
        }
        int sum = 0;
        int c = 1;
        if(str.charAt(0) == '-'){
            c = -1;
            sum = num(str,1);
        }else if(str.charAt(0) == '+'){
            sum = num(str,1);
        }else{
            sum = num(str,0);
        }
        return c * sum;
    }

    public static int num(String str,int i) {
        int sum = 0;
        for(;i<str.length();i++){
            if(str.charAt(i) < '0' || str.charAt(i) > '9'){
                return 0;
            }
            sum = sum * 10 + (str.charAt(i)-'0');
        }
        return sum;
    }
}
